package com.common.frame.adapter


import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.common.frame.R
import com.common.frame.base.BaseAdapter
import com.common.frame.bean.NavigationItem
import com.common.frame.databinding.ItemNavigationBinding
import com.common.frame.extension.getColor

class NavigationAdapter(data: MutableList<NavigationItem>) :
    BaseAdapter<NavigationItem, ItemNavigationBinding>(R.layout.item_navigation, data) {
    var position = 0

    override fun convert(holder: BaseDataBindingHolder<ItemNavigationBinding>, item: NavigationItem) {
        holder.dataBinding?.run {
            val isSelect = position == holder.adapterPosition
            ivTab.setImageResource(if (isSelect) item.selectIcon else item.normalIcon)
            tvTab.text = item.text
            tvTab.isSelected = isSelect
            if (isSelect){
                itemNavigationBar.setBackgroundColor(R.color.color_6666.getColor())
            }else{
                itemNavigationBar.setBackgroundColor(R.color.color_3333.getColor())
            }
        }
    }

    fun setSelect(pos: Int) {
        position = pos
        notifyDataSetChanged()
    }



}